package org.gesplan.ui;

import org.gesplan.entity.Work;


/**
 *
 * @author Roger
 */
public class WorkAddFrame extends javax.swing.JInternalFrame {

    private String serviceId;
    private String serviceDescription;    
    private Work work;   
    private String action;
    
    
    public WorkAddFrame(String serviceId, String serviceDescription) {
        this.serviceId = serviceId;
        this.serviceDescription = serviceDescription;        
        this.action = "new";
        initComponents();
        initConfig();
    }

    public WorkAddFrame(Work work, String action) {
        this.work = work;
        this.action = action;
        initComponents();
        initConfig();
    }
    
    public WorkAddFrame() {
        initComponents();
        initConfig();
    }

    private void initConfig(){
        String title = "Comunicat de treball";
        if (serviceDescription != null){
            title += ": " + serviceDescription;
        }
        this.setTitle(title);    
        workAddPanel1.setServiceId(serviceId); 
        workAddPanel1.setWork(work);
        workAddPanel1.setAction(action);
        workAddPanel1.setParent(this);
        workAddPanel1.initCombos();
        workAddPanel1.initWork();
    }
    
    
    public void setWork(Work work, String action){
        workAddPanel1.resetFields();
        workAddPanel1.setWork(work);     
        workAddPanel1.setAction(action);        
        workAddPanel1.initWork();        
    }
    
    
    public void close(){
        this.setVisible(false);
        this.dispose();
    }
    
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        workAddPanel1 = new org.gesplan.ui.WorkAddPanel();

        getContentPane().add(workAddPanel1, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private org.gesplan.ui.WorkAddPanel workAddPanel1;
    // End of variables declaration//GEN-END:variables

}